package 题目集.并查集;

import java.util.Scanner;

public class 植物园 {
    static int[] parent;
    static int[] size;
    static int cnt; //记录集合的数量
    static int n,m;

    public static void union(int o1,int o2){
        o1=find(o1);    //找到o1的根节点
        o2=find(o2);    //找到o2的根节点
        if (o1==o2) return;
        if (size[o1]>size[o2]) {
            parent[o2] = o1;
            size[o1] += size[o2];
        }else {
            parent[o1] = o2;
            size[o2] += size[o1];
        }
        cnt--;
    }
    public static int find(int x){
        if (parent[x]==0) return x;
        return parent[x]=find(parent[x]);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        cnt=n*m;
        parent=new int[cnt+1];
        size=new int[cnt+1];
        int k=sc.nextInt();
        while (k-- > 0) {
            union(sc.nextInt(),sc.nextInt());
        }
        System.out.println(cnt);
    }
}
